# config/settings.py
import os
from pathlib import Path

# 获取项目根目录
BASE_DIR = Path(__file__).resolve().parent.parent


class Settings:

    # AIGC 集成可选(deepseek coze dashscope)
    AIGC_PROVIDER = os.getenv("AIGC_PROVIDER", "dashscope")  # 默认使用Coze

    # Coze API 配置
    COZE_API_KEY = os.getenv("COZE_API_KEY", "cztei_hMn5gVaGQRXO2Y65YgcKvy27npBT8plWMBZmUdLYv6S3maPwWZ3vYaiS9d9Y2oTkR")
    COZE_MODEL = "coze-pro"
    COZE_API_ENDPOINT = "https://api.coze.cn/v1/conversation/create"

    # DEEPSEEK API 配置
    DEEPSEEK_API_KEY = os.getenv("DEEPSEEK_API_KEY", "sk-bfb7f38d394b4b288470c288a31d3490")
    DEEPSEEK_MODEL = "deepseek-chat"
    DEEPSEEK_API_ENDPOINT = "api.deepseek.com"

    # 阿里云百炼的API 配置
    DASHSCOPE_API_KEY = "sk-53d97a4e7efa467b9c4d8bcd7bb4fb11"
    DASHSCOPE_MODEL = "deepseek-r1"
    DASHSCOPE_API_ENDPOINT = "dashscope.aliyuncs.com"

    # 路径配置 - 使用绝对路径
    TESTS_DIR = BASE_DIR / "tests"
    GENERATED_TESTS_DIR = TESTS_DIR / "generated"
    IMPROVED_TESTS_DIR = TESTS_DIR / "improved"
    REPORTS_DIR = BASE_DIR / "reports"
    MANUAL_TESTS_DIR = TESTS_DIR / "manual"

    # 默认测试路径
    DEFAULT_TEST_PATH = str(TESTS_DIR)  # 添加默认测试路径

    # 测试结果文件
    TEST_RESULTS_FILE = REPORTS_DIR / "test_results.json"
    FINAL_REPORT_FILE = REPORTS_DIR / "final_report.html"

    # 其他设置
    MAX_RETRIES = 3
    TIMEOUT = 30

    @classmethod
    def create_directories(cls):
        """确保所有必要的目录都存在"""
        cls.GENERATED_TESTS_DIR.mkdir(parents=True, exist_ok=True)
        cls.IMPROVED_TESTS_DIR.mkdir(parents=True, exist_ok=True)
        cls.REPORTS_DIR.mkdir(parents=True, exist_ok=True)
        cls.MANUAL_TESTS_DIR.mkdir(parents=True, exist_ok=True)


# 初始化时创建目录
Settings.create_directories()